package com.mrd.netty.six;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Random;

/**
 * @author jack
 * @data 2019/4/28 15:04
 */
public class TestClientHandler extends SimpleChannelInboundHandler <String>{
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        System.out.println(msg);
    }


    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        int randomInt = new Random().nextInt(3);
        MyDataInfo.MyMessage.Builder myMessage = null;
        switch (randomInt) {
            case 0 :
                myMessage = MyDataInfo.MyMessage.newBuilder()
                .setDataTyp(MyDataInfo.MyMessage.DataType.personType)
                        .setPerson(MyDataInfo.Person.newBuilder()
                                .setAge(20)
                                .setAddress("beijing")
                                .setName("是的")
                                .build());

            case 1 :
                myMessage = MyDataInfo.MyMessage.newBuilder()
                        .setDataTyp(MyDataInfo.MyMessage.DataType.DogType)
                        .setDog(MyDataInfo.Dog.newBuilder()
                                .setName("小黄")
                                .setAge(15));
            case 2 :
                myMessage = MyDataInfo.MyMessage.newBuilder()
                        .setDataTyp(MyDataInfo.MyMessage.DataType.CatType)
                        .setCat(MyDataInfo.Cat.newBuilder()
                                .setCity("BEIJING")
                                .setName("jsdf")
                        );

        }



        ctx.channel().writeAndFlush(myMessage);
    }
}
